package my.georings.data;

import android.content.Context;
import android.content.SharedPreferences;


public class Settings extends Object{

	
	private int[] intervals = {2*60*1000, 5*60*1000, 10*60*1000};
	
	private int interval = 2*60*1000;//5*60*1000; // 5 min
	private boolean gps = true;
	private boolean reduceInterval = true;
	private boolean stopAutomatically = true;
	
	private String FILE = "GeoPrfs";
	
	
	
	public Settings(){
	}
	
	public void serialize(Context context){
		SharedPreferences settings = context.getSharedPreferences(FILE, 0);
		SharedPreferences.Editor edit = settings.edit();
		edit.putInt("interval", interval);
		edit.putBoolean("gps", gps);
		edit.putBoolean("reduce", reduceInterval);
		edit.putBoolean("auto", stopAutomatically);
		edit.commit();
	}
	
	public void deserialize(Context context){
		SharedPreferences settings = context.getSharedPreferences(FILE, 0);
		if(settings.getAll().size() == 0)
			return;
		interval = settings.getInt("interval", interval);
		gps = settings.getBoolean("gps", gps);
		reduceInterval = settings.getBoolean("reduce", reduceInterval);
		stopAutomatically = settings.getBoolean("auto", stopAutomatically);
	}
	
	
	public int getInterval() {
		return interval;
	}
	public void setInterval(int interval) {
		this.interval = interval;
	}
	public boolean isGps() {
		return gps;
	}
	public void setGps(boolean gps) {
		this.gps = gps;
	}
	public boolean isReduceInterval() {
		return reduceInterval;
	}
	public void setReduceInterval(boolean reduceInterval) {
		this.reduceInterval = reduceInterval;
	}

	public int getIntervalIndex(){
		for(int i = 0; i < intervals.length; ++i)
			if(interval == intervals[i])
				return i;
		return 0;
	}
	
	public void setIntervalIndex(int index){
		interval = intervals[index];
	}
	
	

	public boolean isStopAutomatically() {
		return stopAutomatically;
	}

	public void setStopAutomatically(boolean stopAutomatically) {
		this.stopAutomatically = stopAutomatically;
	}

	public void copyFrom(Settings from){
		gps = from.isGps();
		interval = from.getInterval();
		reduceInterval = from.isReduceInterval();
		stopAutomatically = from.isStopAutomatically();
	}

}
